<?php

namespace App\Console\Commands\Kms;

use App\Library\FeiShu\SendFs;
use App\Models\Kms\KmsIosCode;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;

class CheckIosDownloadCode extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'kms:checkIosDownloadCode';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '检查夸父运营IOS下载code-数量不足提示重新导入';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        //        $count = Redis::sCard(KmsIosCode::KMS_IOS_DOWNLOAD_CODE);
        $count = KmsIosCode::query()
            ->where('status', KmsIosCode::STATUS_NOT_USE)// 未使用
            ->count();

        Log::info('夸父运营IOS下载code数量：' . $count);
        if ($count < 1000) {
            SendFs::newRobot()
                ->setTitleContent("夸父运营IOS下载code-数量不足请重新导入", "剩余：" . $count)
                ->setAtUid('346gc6ea') //桃之助
                ->send();
        }
    }
}
